package com.pf.java.NetworkTest;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * InetAddress
 *
 * ClassName:InetAddressDemo
 * Package:com.pf.java.NetworkTest
 *
 * @author: pf
 * @date: 2021/11/24-15:36
 */
public class InetAddressDemo {

    public static void main(String[] args) throws IOException {
        InetAddress baidu = InetAddress.getByName("www.baidu.com");

        System.out.println(baidu.getHostAddress());//得到IP
        System.out.println(baidu.isReachable(2000));//是否可达

        InetAddress local = InetAddress.getByAddress(new byte[]{127, 0, 0, 1});
        System.out.println(local.getHostName());
        System.out.println(local.isReachable(2000));


    }

}
